/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package GUI;

import bl.Berechnungen;

/**
 *
 * @author Vodo
 */
public class VerrechnungDLG extends javax.swing.JDialog {

    private Berechnungen berechnung;
    /**
     * Creates new form VerrechnungDLG
     */
    public VerrechnungDLG(java.awt.Frame parent, boolean modal) {
        super(parent, modal);
        initComponents();
        
        berechnung = Berechnungen.getInstance();

    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jTextField2 = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        jTextField6 = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        jTextField4 = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        jPanel5 = new javax.swing.JPanel();
        jRadioButton3 = new javax.swing.JRadioButton();
        jRadioButton4 = new javax.swing.JRadioButton();
        jLabel1 = new javax.swing.JLabel();
        jTextField5 = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jPanel3 = new javax.swing.JPanel();
        jPanel4 = new javax.swing.JPanel();
        jRadioButton1 = new javax.swing.JRadioButton();
        jRadioButton2 = new javax.swing.JRadioButton();
        jCheckBox1 = new javax.swing.JCheckBox();
        jComboBox2 = new javax.swing.JComboBox();
        jLabel9 = new javax.swing.JLabel();
        jTextField7 = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        jTextField8 = new javax.swing.JTextField();
        jPanel2 = new javax.swing.JPanel();
        btFertig = new javax.swing.JButton();
        btAbbrechen = new javax.swing.JButton();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Verrechnung"));
        jPanel1.setLayout(new java.awt.GridLayout(0, 2));

        jLabel2.setText("Überstunden 50%");
        jPanel1.add(jLabel2);
        jPanel1.add(jTextField2);

        jLabel8.setText("Überstunden 100%");
        jPanel1.add(jLabel8);
        jPanel1.add(jTextField6);

        jLabel6.setText("Akonto");
        jPanel1.add(jLabel6);
        jPanel1.add(jTextField4);

        jLabel7.setText("Service-Entgeld");
        jPanel1.add(jLabel7);

        jPanel5.setLayout(new java.awt.GridLayout(1, 0));

        jRadioButton3.setText("Ja");
        jPanel5.add(jRadioButton3);

        jRadioButton4.setText("Nein");
        jPanel5.add(jRadioButton4);

        jPanel1.add(jPanel5);

        jLabel1.setText("Gefahrene Kilometer");
        jPanel1.add(jLabel1);
        jPanel1.add(jTextField5);

        jLabel3.setText("Kilometergeld");
        jPanel1.add(jLabel3);
        jPanel1.add(jTextField1);

        jLabel4.setText("Zusatzinformation");
        jPanel1.add(jLabel4);

        jPanel3.setLayout(new java.awt.BorderLayout());

        jPanel4.setLayout(new java.awt.GridLayout(2, 0));

        jRadioButton1.setText("Motorrad");
        jPanel4.add(jRadioButton1);

        jRadioButton2.setText("PKW");
        jPanel4.add(jRadioButton2);

        jCheckBox1.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jCheckBox1.setText("Beifahrer");
        jCheckBox1.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        jCheckBox1.setIconTextGap(5);
        jCheckBox1.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                onBeifahrerChanged(evt);
            }
        });
        jPanel4.add(jCheckBox1);

        jComboBox2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "1", "2", "3", "4" }));
        jComboBox2.setEnabled(false);
        jPanel4.add(jComboBox2);

        jPanel3.add(jPanel4, java.awt.BorderLayout.CENTER);

        jPanel1.add(jPanel3);

        jLabel9.setText("Taggeld");
        jPanel1.add(jLabel9);
        jPanel1.add(jTextField7);

        jLabel10.setText("Nächtigungsgeld");
        jPanel1.add(jLabel10);
        jPanel1.add(jTextField8);

        getContentPane().add(jPanel1, java.awt.BorderLayout.CENTER);

        jPanel2.setLayout(new java.awt.GridLayout(1, 0));

        btFertig.setFont(new java.awt.Font("Verdana", 1, 18)); // NOI18N
        btFertig.setText("Übernehmen");
        btFertig.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btFertigonUebernehmen(evt);
            }
        });
        jPanel2.add(btFertig);

        btAbbrechen.setFont(new java.awt.Font("Verdana", 1, 18)); // NOI18N
        btAbbrechen.setText("Abbrechen");
        btAbbrechen.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btAbbrechenonAbbrechen(evt);
            }
        });
        jPanel2.add(btAbbrechen);

        getContentPane().add(jPanel2, java.awt.BorderLayout.SOUTH);

        jMenu1.setText("Hilfe");
        jMenuBar1.add(jMenu1);

        setJMenuBar(jMenuBar1);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btFertigonUebernehmen(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btFertigonUebernehmen
        String str = jTextField2.getText().replace(',', '.');
        
        try{
        if(!str.isEmpty())
            berechnung.setUeberstudenHalb(true);
        else
            berechnung.setUeberstudenHalb(false);
        berechnung.setUeberstundenAnz(Double.parseDouble(str));
        }catch(NumberFormatException ex){
            
        }
        
        try{
        str = jTextField6.getText().replace(',', '.');
        if(!str.isEmpty())
            berechnung.setUeberstudenVoll(true);
        else
            berechnung.setUeberstudenVoll(false);
        berechnung.setUeberstundenAnz(Double.parseDouble(str));
        }catch(NumberFormatException ex){
            
        }
        
        try{
        str = jTextField4.getText().replace(',', '.');
        berechnung.setAkontozahlung(Double.parseDouble(str));
        }catch(NumberFormatException ex){
            
        }
        
        try{
        if(jRadioButton3.isSelected())
        berechnung.setsEndgelt(10.55);
        else
            berechnung.setsEndgelt(0.0);
        }catch(NumberFormatException ex){
            
        }
        
        try{
        str = jTextField5.getText().replace(',', '.');
        berechnung.setKilometer(Double.parseDouble(str));
        }catch(NumberFormatException ex){
            
        }
            berechnung.setPkw(jRadioButton1.isSelected());
        berechnung.setMotorrad(jRadioButton2.isSelected());
        
        try{
        str = jTextField1.getText().replace(',', '.');
        berechnung.setKilometerGeldMotorrad(Double.parseDouble(str));
        berechnung.setKilometerGeldPKW(Double.parseDouble(str));
        }catch(NumberFormatException ex){
            
        }
        
        try{
        str = jTextField7.getText().replace(',', '.');
        berechnung.setTagesGeld(Double.parseDouble(str));
        }catch(NumberFormatException ex){
            
        }
        
        try{
        str = jTextField8.getText().replace(',', '.');
        berechnung.setNaechtigunsGeld(Double.parseDouble(str));
        }catch(NumberFormatException ex){
            
        }
        berechnung.setZusaetlichePersonen(Double.parseDouble((String)jComboBox2.getSelectedItem()));
        /*
        private double avabaeab = 565.88; //Alleinverdieneranteil
    private double grenzsteursatz = 43.21429; //Grenzsteursatz der Gehaltsstufe
    private double gehalt = 4560; //Gehalt oder Lohn
    private double svProzentsatz = 18.07; // Prozentsatz 18,07 oder 18,2
    private double freibetrag = 55.4; // freibetrag
    private double sEndgelt ; //Serviceendgelt
    private boolean gewerksschaftsbeitrag = true;
    private double gb;
    private double auszahlung;
    private double pp; //pendlerpauschale
    private double akontozahlung;
    private double ueberstundenteiler;
    private double ueberstundenAnz;
    private double uezFrei;
    private double sachbezug1;
    private double sachbezug2;
    private double sachbezug3;
    private double zusaetlichePersonen = 0;
    private double anzReiseTage;
    private double aufwandentschaedigung;
    private double urlaubsgeld = 4560;
    private double weihnachtsgeld;*/
        this.dispose();
    }//GEN-LAST:event_btFertigonUebernehmen

    private void btAbbrechenonAbbrechen(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btAbbrechenonAbbrechen
        this.setVisible(false);
        this.dispose();
    }//GEN-LAST:event_btAbbrechenonAbbrechen

    private void onBeifahrerChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_onBeifahrerChanged
        jComboBox2.setEnabled(jCheckBox1.isSelected());
    }//GEN-LAST:event_onBeifahrerChanged

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(VerrechnungDLG.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(VerrechnungDLG.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(VerrechnungDLG.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(VerrechnungDLG.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the dialog */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                VerrechnungDLG dialog = new VerrechnungDLG(new javax.swing.JFrame(), true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {
                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btAbbrechen;
    private javax.swing.JButton btFertig;
    private javax.swing.JCheckBox jCheckBox1;
    private javax.swing.JComboBox jComboBox2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JRadioButton jRadioButton1;
    private javax.swing.JRadioButton jRadioButton2;
    private javax.swing.JRadioButton jRadioButton3;
    private javax.swing.JRadioButton jRadioButton4;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField2;
    private javax.swing.JTextField jTextField4;
    private javax.swing.JTextField jTextField5;
    private javax.swing.JTextField jTextField6;
    private javax.swing.JTextField jTextField7;
    private javax.swing.JTextField jTextField8;
    // End of variables declaration//GEN-END:variables
}
